<?php
include_once("codelibrary/inc/variables.php");
include_once("session.php");
include_once("codelibrary/inc/functions.php");
include('includes/header.php');

$business_id = $_SESSION['business_id'];

$date_passed = $_REQUEST['selected_appt_date'];
$selected_staff_id = $_REQUEST['selected_staff_id'];
$selected_start_time = $_REQUEST['selected_start_time'];
$timefrom_table = $_REQUEST['timefrom_table'];
$timeto_table = $_REQUEST['timeto_table'];

if(isset($_REQUEST['finalize']))
{
 	$customer_id=$_REQUEST['TR_Customer'];
	$staff_id=$_REQUEST['TR_StaffMember'];
	$service_id=$_REQUEST['TR_Service'];
	$duration=$_REQUEST['TR_Duration'];
	$apptdate=$_REQUEST['TR_AppointmentDate']; 
	$apptstarttime=$_REQUEST['TR_AppointmentTime'];
	list($apptendtime,$apptstartseconds,$apptendseconds) = findendtime($apptstarttime,$duration);
	$apptstatus=$_REQUEST['TR_AppointmentStatus'];
	$cost=$_REQUEST['TN_Cost'];
	$tip=$_REQUEST['TN_Tip'];
	$via=$_REQUEST['TN_Via'];
	$specialinstruction=$_REQUEST['TN_SpecialInstructions'];
	$apptnotes=$_REQUEST['TN_AppointmentNotes'];
	$appttype=$_REQUEST['TN_AppointmentType'];
	$createdemailcustomerstatus=$_REQUEST['TN_CreatedEmailCustomer'];
	$createdemailstaffstatus=$_REQUEST['TN_CreatedEmailStaff'];
	$createdby=$_REQUEST['TN_CreatedByStaffMember'];
	$notes=$_REQUEST['TN_CustomerNotes'];
	$dateadded=date("Y-m-d");
	
	if($notes!='')
	{
		$insert_cn_sql="insert into $customer_notes_table set 
		customer_id='$customer_id',dateadded='$dateadded',notes='$notes'";
	}
	
	mysql_query($insert_cn_sql);
	
	$insert_fa_sql="insert into $finalize_appointment_table set business_id='$business_id' , customer_id='$customer_id' , 
	staff_id='$staff_id' , service_id='$service_id' , duration='$duration' , apptdate='$apptdate' , 
	apptstarttime='$apptstarttime' , apptendtime='$apptendtime' , apptstartseconds='$apptstartseconds' , 
	apptendseconds='$apptendseconds' , 
	apptstatus='$apptstatus' , cost='$cost' , tip='$tip' , via='$via' , 
	specialinstruction='$specialinstruction', apptnotes='$apptnotes' , appttype='$appttype' , 
	customeremailstatus='$customeremailstatus' , staffemailstatus='$staffemailstatus', createdby='$createdby'";
	
	mysql_query($insert_fa_sql);
	
	$appt_id = mysql_insert_id();
	echo "<script>window.location.href='make-appointment.php?msg=Added&appt_id=$appt_id&appt_date=$apptdate';</script>";
	//header("Location: make-appointment.php?msg=Added&appt_id=$appt_id");

}

if(isset($_REQUEST['prev']))
{
        if(isset($_REQUEST['day']) && $_REQUEST['day']!='')
		{
			$displayed_day = $_REQUEST['day'];
		}
		
		if(isset($_REQUEST['month']) && $_REQUEST['month']!='')
		{
			$displayed_month = $_REQUEST['month'];
		}
		
		if(isset($_REQUEST['year']) && $_REQUEST['year']!='')
		{
			$displayed_year = $_REQUEST['year'];
		}
		
    $date_combo_box = date ("Y-m-d", mktime (0,0,0,$displayed_month,$displayed_day,$displayed_year));
    
	$date_passed = AddDay($date_combo_box,-1);
}
if(isset($_REQUEST['next']))
{
    
        if(isset($_REQUEST['day']) && $_REQUEST['day']!='')
		{
			$displayed_day = $_REQUEST['day'];
		}
		
		if(isset($_REQUEST['month']) && $_REQUEST['month']!='')
		{
			$displayed_month = $_REQUEST['month'];
		}
		
		if(isset($_REQUEST['year']) && $_REQUEST['year']!='')
		{
			$displayed_year = $_REQUEST['year'];
		}
    $date_combo_box = date ("Y-m-d", mktime (0,0,0,$displayed_month,$displayed_day,$displayed_year));
    
	$date_passed = AddDay($date_combo_box,1);
}

if(isset($_REQUEST['Go']))
{
   
        if(isset($_REQUEST['day']) && $_REQUEST['day']!='')
		{
			$displayed_day = $_REQUEST['day'];
		}
		
		if(isset($_REQUEST['month']) && $_REQUEST['month']!='')
		{
			$displayed_month = $_REQUEST['month'];
		}
		
		if(isset($_REQUEST['year']) && $_REQUEST['year']!='')
		{
			$displayed_year = $_REQUEST['year'];
		}
		
		$date_passed = date ("Y-m-d", mktime(0, 0, 0, $displayed_month, $displayed_day, $displayed_year));
}

if(isset($_REQUEST['fromcal']))
{
        if(isset($_REQUEST['day']))
		{
			$displayed_day = $_REQUEST['day'];
		}
		else
		{
		    $displayed_day = 1;
		}
		if(isset($_REQUEST['month']) && $_REQUEST['month']!='')
		{
			$displayed_month = $_REQUEST['month'];
		}
		
		if(isset($_REQUEST['year']) && $_REQUEST['year']!='')
		{
			$displayed_year = $_REQUEST['year'];
		}
		
		$date_passed = date ("Y-m-d", mktime(0, 0, 0, $displayed_month, $displayed_day, $displayed_year));
}


?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html dir="LTR" lang="en">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<title>Online Appointment</title>
<script type="text/javascript" src="codelibrary/js/common.Js"></script>
<script type="text/javascript">
function submitform()
{
 
	if(ValidateForm(document.apptform))
	{
	    return true;
	}
	else
	{
	    return false;
	}
}
</script>

<base >
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<title>Staff Management</title>

</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">


<table cellpadding="0" cellspacing="0" border="0">
  <tr>
    <td style="background:url(images/top.gif) repeat-x top; "><table cellpadding="0" cellspacing="0" border="0" style="width:764px" align="center">
        <tr>
          <td><table cellpadding="0" cellspacing="0" border="0" style="height:57">
              <tr>
                <td height="57"><table cellpadding="0" cellspacing="0" border="0" style="height:1 ">
                    <tr>
                      <td style="width:468px" height="1"></td>
                      <td height="1"></td>
                    </tr>
                  </table>
                  <table cellpadding="0" cellspacing="0" border="0" style="height:3 ">
                    <tr>
                      <td height="3" valign="top" bgcolor="#2A2A2A"><a href="make-appointment.php"><img src="images/appointment1.gif" width="123" height="25" border="0" align="absmiddle"></a><span><a href="customer-view-details.php" class="toptxt-mOver">&nbsp;Customers&nbsp;</a></span> <img src="images/seprator1.gif" width="11" height="25" align="absmiddle">&nbsp;&nbsp;<a href="staff_members.php" class="toptxt-mOver">Staff Members&nbsp;</a><span class="leftmenutxt">&nbsp;<img src="images/seprator1.gif" width="11" height="25" align="absmiddle"></span> &nbsp;<span>&nbsp;<a href="service-view-details.php" class="toptxt-mOver" >Services&nbsp;</a>&nbsp;<img src="images/seprator1.gif" width="11" height="25" align="absmiddle">&nbsp;&nbsp;&nbsp;<a href="reports-view-details.php" class="toptxt-mOver">Reports&nbsp;</a>&nbsp;<img src="images/seprator1.gif" width="11" height="25" align="absmiddle">&nbsp;&nbsp;&nbsp;<a href="update-company-location.php" class="toptxt-mOver">Company&nbsp;</a>&nbsp;<img src="images/seprator1.gif" width="11" height="25" align="absmiddle">&nbsp;&nbsp;&nbsp;<a href="location-view-details.php" class="toptxt-mOver">Lists&nbsp;</a>&nbsp;<img src="images/seprator1.gif" width="11" height="25" align="absmiddle">&nbsp;&nbsp;&nbsp;<a href="help.php" class="toptxt-mOver">Help&nbsp;</a> <img src="images/seprator1.gif" width="11" height="25" align="absmiddle">&nbsp; &nbsp;<a href="logout.php" class="toptxt-mOver">Logout</a></span><br></td>
                    </tr>
                  </table></td>
              </tr>
            </table>
            
            
          </td>
        </tr>
        <tr>
          <td>
            
            
            <table border="0" width="105%" cellspacing="0" cellpadding="0">
              <tr>
                <td valign="top" class="col_left">
                  <table border="0"cellspacing="0" cellpadding="0" class="box_width_left">
                    <tr>
                      <td width="100%"><table border="0" cellspacing="0" cellpadding="0">
                          <tr>
                            <td><table border="0" width="100%" cellspacing="0" cellpadding="0" class="">
                                <tr>
                                  <td><table border="0" width="100%" cellspacing="0" cellpadding="0"  class="" height="91">
                                      <tr>
                                        <td align="center" height="91"><img border="0" src="images/logo.jpg" width="208" height="86"></td>
                                      </tr>
                                    </table></td>
                                </tr>
                              </table></td>
                          </tr>
                          <tr>
                            <td><table border="0" width="100%" cellspacing="0" cellpadding="0"  class="box_header_txt" height="48">
                                <tr>
                                  <td style="background-image: url(images/1_bg2-2.gif)" height="1"><p style="margin-top: 16"> </td>
                                </tr>
                              </table>
                              <table border="0" width="100%" cellspacing="0" cellpadding="0"   style="border-bottom:12px solid #ffffff;">
                                <tr>
                                  <td><table border="0" width="100%" cellspacing="0" cellpadding="0"  style="margin-bottom:0px;background:#7C7C7C url(images/1_line.gif) no-repeat left bottom;" >
                                      <tr>
                                        <td  style="padding:3px 16px 8px 25px;">
                                          <table width="100%" border="0">
                                            <tr>
                                              <td><?php
                include(HC_Controls);
          ?>
                                              </td>
                                            </tr>
                                          </table>
                                          </td>
                                      </tr>
                                    </table></td>
                                </tr>
                              </table></td>
                          </tr>
                          
                          <tr>
                            <td class="">&nbsp;</td>
                          </tr>
                          
                        </table></td>
                      <td><img src="images/spacer.gif" border="0" alt="" width="15" height="1"></td>
                    </tr>
                  </table>
                  
                </td>
                
                <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0"  class="cont_header_txt">
                    <tr>
                      <td><table border="0" cellpadding="0" cellspacing="0" bgcolor="#EAEAEA" class="cont_header_txt">
                          <tr>
                            <td><img src="images/1_q1.gif" border="0" alt="" width="45" height="39"></td>
                            <td style="width:100%">Finalize Appointment</td>
                            <td><img src="images/1_q2.gif" border="0" alt="" width="10" height="39"></td>
                          </tr>
                        </table></td>
                    </tr>
                  </table>
                  
                  <table cellpadding="0" cellspacing="0" border="0" style="border:0px solid #DEDEDE; border-width:0px 1px 0px 1px;">
                    <tr>
                      <td style="background:#ffffff;border:0px solid #ffffff; border-width:18px 5px 10px 5px;"><!-- new_products //-->
                        <table border="0" width="100%" cellspacing="0" cellpadding="0" class="box_width_cont product">
                          <tr>
                            <td><form name="datefrm" action="make-appointment.php?staff_id=<?=$staff_id;?>&amp;type=<?=$type;?>" method="post">
                                <br/>
                                <br/>
                                <input type="submit" name="prev" value="<<" class="button">
                                <input type="submit" name="next" value=">>" class="button">
                                <?php
datelisting($date_passed);
?>
                                &nbsp;&nbsp;
                                <input type="submit" name="Go" value="Go" class="button" />
                                <br />
                                <br />
                                <?php
                                    $displayed_date_array = explode("-",$date_passed);
									$displayed_year = $displayed_date_array[0];
									$displayed_month = $displayed_date_array[1];
									$displayed_day = $displayed_date_array[2];
									$month_desc = date ("M", mktime(0, 0, 0, $displayed_month, $displayed_day, $displayed_year));
									$weekday = date("l", mktime(0, 0, 0, $displayed_month, $displayed_day, $displayed_year));
									echo $weekday." ".$month_desc." ".$displayed_day.", ".$displayed_year;
								?>
                              </form></td>
                          </tr>
                          <tr>
                            <td>&nbsp;</td>
                          </tr>
                          <tr>
                            <td><table width="" border="1" cellpadding="0" cellspacing="0" bordercolor="#FFDBCA" class="table">
                                <tr>
                                  <td height="25" colspan="2" bgcolor="#EAEAEA" class="H1">Make Appointment </td>
                                </tr>
                                <tr>
                                  <td >&nbsp;</td>
                                </tr>
								
                                <form name="apptform" method="post" action="" onSubmit="return submitform();">
								<tr>
                                  <td align="right"><input type="submit" name="finalize" value="Finalize Appointment" class="button"></td>
                                </tr>
								<tr>
                                  <td >&nbsp;</td>
                                </tr>
                                  <tr>
                                    <td ><table width="" border="1" cellpadding="0" cellspacing="0" bordercolor="#FFDBCA" class="table">
                                        <tr>
                                          <td width="67%" height="25" class="simpletxt">&nbsp;&nbsp;<strong>Select Customer</strong></td>
                                          <td width="67%">
										   <?php
											$getcust_sql = "select * from customer_info where business_id='$business_id'";
											$getcust_query = mysql_query($getcust_sql);
											?>
                                            <select name="TR_Customer" onChange="javascript:document.apptform.submit()">
                                              <option value="">Select Customer</option>
                                              <?php
												while($getcust_data=mysql_fetch_array($getcust_query))
												{
													$cust_id=$getcust_data["customer_id"];
													$full_name=$getcust_data["lastname"].", ".$getcust_data["firstname"];
													echo "<option value='$cust_id'";
													if(isset($TR_Customer)&&($TR_Customer=="$cust_id"))
															{		
																echo " selected";
															}
													echo ">".$full_name."</option>";
												}
											 ?>
                                            </select>
                                          </td>
                                          <td width="67%" height="25" class="simpletxt">&nbsp;&nbsp;<strong>With</strong></td>
                                          <td width="67%">
										  <?php
										  $getAllStaff_sql = "select * from staff where business_id='$business_id'";
										  $getAllStaff_query = mysql_query($getAllStaff_sql);
										  ?>
										  <select name="TR_StaffMember" onChange="javascript:document.apptform.submit()">
                                              <option value="">Select Staff Member</option>
											  <?php
											  
											  while($getAllStaff_data = mysql_fetch_array($getAllStaff_query))
											  {
											        $staffid=$getAllStaff_data["staff_id"];
													$firstname=$getAllStaff_data["first_name"];
													echo "<option value='$staffid'";
													if(isset($TR_StaffMember)&&($TR_StaffMember=="$staffid"))
													{		
																echo " selected";
													}
													
													
															
													echo ">".$firstname."</option>";
 
											  }
											  ?>
                                             
                                            </select>
                                          </td>
                                        </tr>
                                        <tr>
                                          <td width="67%" height="25" class="simpletxt">&nbsp;&nbsp;<strong>First Name</strong></td>
                                          <td width="67%">
								   <?php
								
									$getcustdetails_sql = "select * from customer_info where customer_id='".$_REQUEST['TR_Customer']."'";
									$getcustdetails_query = mysql_query($getcustdetails_sql);
									$getcustdetails_data = mysql_fetch_array($getcustdetails_query);
									?>
                                            <input name="f_name" type="text" id="f_name" value="<?=$getcustdetails_data['firstname'];?>">
                                          </td>
										  <td width="67%" height="25" class="simpletxt">&nbsp;&nbsp;<strong>Service</strong></td>
                                          <td width="67%">
										  <select name="TR_Service" onChange="javascript:document.apptform.submit()">
                                              <option value="">Select Service</option>
										  <?php
								  if(isset($_REQUEST['TR_StaffMember']) && $_REQUEST['TR_StaffMember']!='')
								  {
								    $getstaffoffered_sql = "select * from staff_offered where staff_id='".$_REQUEST['TR_StaffMember']."'";
									$getstaffoffered_query = mysql_query($getstaffoffered_sql);
									while($getstaffoffered_data = mysql_fetch_array($getstaffoffered_query))
									{
									     $service_id = $getstaffoffered_data['service_id'];
										 $getservice_sql = "select * from services where service_id='$service_id'";
									     $getservice_query = mysql_query($getservice_sql);
										 $getservice_data=mysql_fetch_array($getservice_query);
										 $description=$getservice_data["description"];
										 $title=$getservice_data["title"];
										 echo "<option value='$service_id'";
										 if(isset($TR_Service)&&($TR_Service=="$service_id"))
										 {		
											echo " selected";
										 }
										 echo ">".$title."</option>";
									}
								  }
								  else
								  {
								         $getservice_sql = "select * from services where business_id='$business_id'";
									     $getservice_query = mysql_query($getservice_sql);
										 while($getservice_data=mysql_fetch_array($getservice_query))
										 {
										     $service_id=$getservice_data["service_id"];
											 $description=$getservice_data["description"];
											 $title=$getservice_data["title"];
											 echo "<option value='$service_id'";
											 if(isset($TR_Service)&&($TR_Service=="$service_id"))
											 {		
												echo " selected";
											 }
											 echo ">".$title."</option>";
										 }
								  }
									?>
                                           
                                            </select>
                                          </td>
                                        </tr>
										<tr>
                                          <td width="67%" height="25" class="simpletxt">&nbsp;&nbsp;<strong>Last Name</strong></td>
                                          <td width="67%">
                                            <input name="l_name" type="text" id="l_name" value="<?=$getcustdetails_data['lastname'];?>">
                                          </td>
										  <td width="67%" height="25" class="simpletxt">&nbsp;&nbsp;<strong>Duration</strong></td>
                                          <td width="67%">
                                           <SELECT name="TR_Duration">
                                        <OPTION>--Select Duration--</OPTION>
                                        <?php
										$getduration_sql = "select duration from services where service_id='".$_REQUEST['TR_Service']."'";
										$getduration_query = mysql_query($getduration_sql);
										$getduration_data = mysql_fetch_array($getduration_query);
										$duration = $getduration_data['duration'];
										
										$interval = "8 minutes"; //from appointment_setting table
										$value_minutes_array = explode(" ",$interval);
										$value_minutes = $value_minutes_array[0];
										$start_seconds = $value_minutes*60;
										$end_seconds = 24*3600;
										
										$interval = $value_minutes*60;
										
										$increment = $value_minutes*60;
										
										while($start_seconds<=$end_seconds)
										{
										   $minute_value = $start_seconds/60;
										   
										   if($minute_value<60)
										   {
											   $displayed_value = $minute_value." minutes";
												?>
												<option value="<?=$displayed_value;?>" <? if($duration==$displayed_value){echo "selected";}?>><?=$displayed_value;?></option>
												<?php
										   }
										   else
										   {
											   $hour_displayed_value = floor($minute_value/60);
											   $minute_displayed_value = $minute_value%60;
											   
											   if($minute_displayed_value!=0)
											   {
											   
												   $displayed_value = $hour_displayed_value." hours ".$minute_displayed_value." minutes";
											   }
											   else
											   {
												   $displayed_value = $hour_displayed_value." hours ";
											   }
											   ?>
												<option value="<?=$displayed_value;?>" <? if($duration==$displayed_value){echo "selected";}?>><?=$displayed_value;?></option>
												<?php
										   }
										   
										   $start_seconds = $start_seconds + $increment;
										}
										?>
                                      </SELECT>
                                          </td>
                                        </tr>
										<tr>
                                          <td width="67%" height="25" class="simpletxt">&nbsp;&nbsp;Address</td>
                                          <td width="67%" class="simpletxt">
                                            <textarea name="TN_Address" rows="3" cols="15"><?=$getcustdetails_data['address'];?>
											</textarea>
                                          </td>
										  <td width="67%" height="25" class="simpletxt">&nbsp;&nbsp;<strong>Date</strong></td>
                                          <td width="67%">
										  <SELECT name="TR_AppointmentDate">
                                          <OPTION>--Select Appointment Date--</OPTION>
										  <?php
										  $dates = DatesBetween($date_passed,"2008-07-17");
										  $count  = count($dates);
										 
										  for($i=0; $i<$count; $i++)
										  {
										     
										     $date_ymd = $dates[$i];
											 $date_ymd_array = explode("-",$date_ymd);
											 $date_ymd_year = $date_ymd_array[0];
											 $date_ymd_month = $date_ymd_array[1];
											 $date_ymd_day = $date_ymd_array[2];
											 $month_desc = date ("M", mktime(0, 0, 0, $date_ymd_month, $date_ymd_day, $date_ymd_year));
											 $weekday = date("l", mktime(0, 0, 0, $date_ymd_month, $date_ymd_day, $date_ymd_year));
											 $displayed_date_ymd = $weekday." ".$month_desc." ".$date_ymd_day.", ".$date_ymd_year;
        									 ?>
                                        <OPTION  value="<?=$date_ymd;?>" <? if($date_ymd==$date_passed){echo "selected";}?>>
                                        <?=$displayed_date_ymd;?>
                                        </OPTION>
                                        <?php  
    									  }
										  ?>
                                        </SELECT>
                                          </td>
                                        </tr>
										<tr>
                                          <td width="67%" height="25" class="simpletxt">&nbsp;&nbsp;City</td>
                                          <td width="67%">
                                            <input name="TN_City" type="text" id="TN_City" value="<?=$getcustdetails_data['city'];?>">
                                          </td>
										  <td width="67%" height="25" class="simpletxt">&nbsp;&nbsp;<strong>Time</strong></td>
                                          <td width="67%">
										  <SELECT name="TR_AppointmentTime">
                                        <OPTION>--Select Appointment Time--</OPTION>
										  <?php
										    $timefrom = substr($timefrom_table, 0, -2);
											$typefrom = substr($timefrom_table,-2);
											$timeto = substr($timeto_table, 0, -2);
											$typeto = substr($timeto_table,-2);
											
											$interval = 15;											
											if($typefrom=="am")
											{
												 $timefrom_array = explode(":",$timefrom);
												 $hourfrom = $timefrom_array[0];
												 $minutefrom = $timefrom_array[1];
												 $secondfrom = 0;
											}
										
											if($typeto=="pm")
											{
												 $timeto_array = explode(":",$timeto);
												 $hourto = 12 + $timeto_array[0];
												 $minuteto = $timeto_array[1];
												 $secondto = 0;
											}

											$start_time = mktime($hourfrom, $minutefrom, $secondfrom, 1, 1, 1970);
											$end_time = mktime($hourto, $minuteto, $secondto, 1, 1, 1970);
											
											
											$num_intervals = floor(($end_time - $start_time) / $interval);
											
											//Build a list of times.
											$buffer_time = $start_time;
											$times[$i]['end'] = $start_time;
											$iso_starttime = date('h:i:s a', $start_time);
											?>
											<OPTION  value="<?=$iso_starttime;?>" <? if($iso_starttime==$selected_start_time){echo "selected";}?>>	
										  <?=$iso_starttime;?>
                                           </OPTION>
                                           <?php
										    for($i = 0; $i < $num_intervals; $i++) 
											{
													if(($i+1)!=$num_intervals)
													{
															$times[$i]['end'] = $buffer_time += $interval;
															
															$iso_timeto[$i]['end'] = date('h:i:s a', $times[$i]['end']);
														
													}
													?>
													  <OPTION  value="<?=$iso_timeto[$i]['end'];?>" <? if($iso_timeto[$i]['end']==$selected_start_time){echo "selected";}?>>	
										  <?=$iso_timeto[$i]['end'];?>
                                           </OPTION> 
												   <?php
													
											}
										   ?>
                                      </SELECT>
                                          </td>
                                        </tr>
										<tr>
                                          <td width="67%" height="25" class="simpletxt">&nbsp;&nbsp;State</td>
                                          <td width="67%">
                                            <input name="TN_State" type="text" id="TN_State" value="<?=$getcustdetails_data['state'];?>">
                                          </td>
										   
										  <td width="67%" height="25" class="simpletxt">&nbsp;&nbsp;<strong>Status</strong></td>
                                          <td width="67%">
										  <?php
											$getapptstatus_sql = "select * from appointment_status_type where business_id='$business_id'";
											$getapptstatus_query = mysql_query($getapptstatus_sql);
									
									      ?>
                                           <select name="TR_AppointmentStatus">
                                              
											  <?php
											  
											  while($getapptstatus_data = mysql_fetch_array($getapptstatus_query))
											  {
											        $as_id=$getapptstatus_data["as_id"];
													$description=$getapptstatus_data["description"];
													echo "<option value='$description'";
													if(isset($TR_AppointmentStatus)&&($TR_AppointmentStatus=="$description"))
													{		
																echo " selected";
													}
													echo ">".$description."</option>";
 
											  }
											  ?>
                                             
                                            </select>
                                          </td>
                                        </tr>
										<tr>
                                          <td width="67%" height="25" class="simpletxt">&nbsp;&nbsp;Zip Code</td>
                                          <td width="67%">
                                            <input name="TN_Zip" type="text" id="TN_Zip" value="<? if($getcustdetails_data['zipcode']!=0){echo $getcustdetails_data['zipcode'];}?>">
                                          </td>
										  <td width="67%" height="25" class="simpletxt">&nbsp;&nbsp;<strong>Cost</strong></td>
										  <?php
								
									$getservicedetails_sql = "select * from services where service_id='".$_REQUEST['TR_Service']."'";
									$getservicedetails_query = mysql_query($getservicedetails_sql);
									$getservicedetails_data = mysql_fetch_array($getservicedetails_query);
									?>
										  <td>
                                           <input name="TN_Cost" type="text" id="TN_Cost" value="<?=$getservicedetails_data['cost'];?>">
										  
                                          </td>
                                        </tr>
										<tr>
                                          <td width="67%" height="25" class="simpletxt">&nbsp;&nbsp;</td>
                                          <td width="67%" height="25" class="simpletxt">&nbsp;&nbsp;</td>
										  <td width="67%" height="25" class="simpletxt">&nbsp;&nbsp;<strong>Tip</strong></td>
										  <td>
                                           <input name="TN_Tip" type="text" id="TN_Tip" value="<?=$getservicedetails_data['tip'];?>">
										  
                                          </td>
                                        </tr>
										<tr>
                                          <td width="67%" height="25" class="simpletxt">&nbsp;&nbsp;</td>
                                          <td width="67%" height="25" class="simpletxt">&nbsp;&nbsp;</td>
										  <td width="67%" height="25" class="simpletxt">&nbsp;&nbsp;<strong>Via</strong></td>
										  
										  <td>
										  <?php
											$getpaytype_sql = "select * from pay_type where business_id='$business_id'";
											$getpaytype_query = mysql_query($getpaytype_sql);
									
									      ?>
                                           <select name="TN_Via">
                                              <option value=""></option>
											  <?php
											  
											  while($getpaytype_data = mysql_fetch_array($getpaytype_query))
											  {
											        $paytype_id=$getpaytype_data["paytype_id"];
													$description=$getpaytype_data["description"];
													echo "<option value='$description'";
													if(isset($TN_Via)&&($TN_Via=="$description"))
													{		
																echo " selected";
													}
													echo ">".$description."</option>";
 
											  }
											  ?>
                                             
                                            </select>
										  
                                          </td>
                                        </tr>
										<tr>
                                          <td width="67%" height="25" class="simpletxt">&nbsp;&nbsp;DayTime Phone</td>
                                          <td width="67%">
                                            <input name="TN_DayPhone" type="text" id="TN_DayPhone" value="<? if($getcustdetails_data['dayphone']!=0){echo $getcustdetails_data['dayphone'];}?>">
                                          </td>
										  <td colspan="2" width="67%" height="25" class="simpletxt"><strong>Special Instructions For Customer</strong><br><br>
                                          
                                           <textarea name="TN_SpecialInstructions" rows="3" cols="15"><? if(isset($TN_SpecialInstructions))echo $TN_SpecialInstructions;?>
											</textarea>
                                          </td>
                                        </tr>
										<tr>
                                          <td width="67%" height="25" class="simpletxt">&nbsp;&nbsp;Evening Phone</td>
                                          <td width="67%">
                                            <input name="TN_EveningPhone" type="text" id="TN_EveningPhone" value="<? if($getcustdetails_data['eveningphone']!=0){echo $getcustdetails_data['eveningphone'];}?>">
                                          </td>
										  <td colspan="2" width="67%" height="25" class="simpletxt"><strong>Appointment Notes (internal only)</strong><br><br>
                                          
                                           <textarea name="TN_AppointmentNotes" rows="3" cols="15"><? if(isset($TN_AppointmentNotes))echo $TN_AppointmentNotes;?>
											</textarea>
                                          </td>
                                        </tr>
										<tr>
                                          <td width="67%" height="25" class="simpletxt">&nbsp;&nbsp;Cell Phone</td>
                                          <td width="67%">
                                            <input name="TN_CellPhone" type="text" id="TN_CellPhone" value="<? if($getcustdetails_data['cellphone']!=0){echo $getcustdetails_data['cellphone'];}?>">
                                          </td>
										  <td  width="67%" height="25" class="simpletxt"><strong>Type</strong></td>
                                          <td>
                                          <SELECT name="TN_AppointmentType">
                                          <option <?php if(isset($TN_AppointmentType) && $TN_AppointmentType=="one-time appointment"){echo "selected";}?>>one-time appointment</option>
                                          <option <?php if(isset($TN_AppointmentType) && $TN_AppointmentType=="recurring appointment"){echo "selected";}?>>recurring appointment</option>
                                         </SELECT>
                                          </td>
                                        </tr>
										<tr>
                                          <td width="67%" height="25" class="simpletxt">&nbsp;&nbsp;Email</td>
                                          <td width="67%">
                                            <input name="TN_Email" type="text" id="TN_Email" value="<?=$getcustdetails_data['email'];?>">
                                          </td>
										  <td colspan="2"  width="67%" height="25" class="simpletxt"><strong>Send Appointment E-mail To Customer</strong>&nbsp;&nbsp;
                                          
                                          <input type="checkbox" name="TN_CreatedEmailCustomer" value="1" checked="checked">
                                          </td>
                                        </tr>
										<tr>
                                          <td width="67%" height="25" class="simpletxt">&nbsp;&nbsp;</td>
                                          <td width="67%">
                                           &nbsp;&nbsp; 
                                          </td>
										  <td colspan="2"  width="67%" height="25" class="simpletxt"><strong>Send Appointment E-mail To Staff Member</strong>&nbsp;&nbsp;
                                          
                                          <input type="checkbox" name="TN_CreatedEmailStaff" value="1" checked="checked">
                                          </td>
                                        </tr>
										<tr>
                                          <td width="67%" height="25" class="simpletxt">&nbsp;&nbsp;</td>
                                          <td width="67%">
                                           &nbsp;&nbsp; 
                                          </td>
										  <td width="67%" height="25" class="simpletxt"><strong>Created By</strong></td>
                                          <td>
                                          <?php
										  $getAllStaff_sql = "select * from staff where business_id='$business_id'";
										  $getAllStaff_query = mysql_query($getAllStaff_sql);
										  ?>
										  <select name="TN_CreatedByStaffMember">
                                              <option value="">Select Staff Member</option>
											  <?php
											  
											  while($getAllStaff_data = mysql_fetch_array($getAllStaff_query))
											  {
											        $staffid=$getAllStaff_data["staff_id"];
													$firstname=$getAllStaff_data["first_name"];
													echo "<option value='$staffid'";
													if(isset($TN_CreatedByStaffMember)&&($TN_CreatedByStaffMember=="$staffid"))
													{		
																echo " selected";
													}
													
													
															
													echo ">".$firstname."</option>";
 
											  }
											  ?>
                                             
                                            </select>
                                          </td>
                                        </tr>
										<tr>
                                          <td colspan="4" width="67%" height="25" class="simpletxt">&nbsp;&nbsp;</td>
                                          
                                        </tr>
										<tr>
                                          <td colspan="4" width="67%" height="25" class="simpletxt">Customer Notes (internal only)<br><br><textarea name="TN_CustomerNotes" rows="3" cols="50"><? if(isset($TN_CustomerNotes))echo $TN_CustomerNotes;?>
											</textarea></td>
                                          
                                        </tr>
										<tr>
                                          <td colspan="4" width="67%" height="25" class="simpletxt">&nbsp;&nbsp;</td>
                                          
                                        </tr>
										<?php
										$getcustomernotes_sql = "select * from $customer_notes_table where customer_id='".$_REQUEST['TR_Customer']."'";
							
										$getcustomernotes_query=mysql_query($getcustomernotes_sql);
										$total_no_of_records = mysql_num_rows($getcustomernotes_query);
										
										if($total_no_of_records>0)
										{	
							?>
										<tr>
                                          <td colspan="4" width="67%" height="25" class="simpletxt">
										    <table width="100%" border="1" align="center" cellpadding="2" cellspacing="1" bordercolor="#FFDBCA" class="table" background-color ="#ffffff">
                                              <tr align="left">
                                               <td nowrap width="14%" align="center"><strong>Date</strong></td>
                                               <td  nowrap width="14%" align="center"><strong>Notes</strong></td>
												</tr>
                                              <?
							
							
			                while($fetchRow=mysql_fetch_array($getcustomernotes_query))
							{
				               
							  
						?>
                                              <tr align="left">
                                                
                                                <td class="smallText" align="center">
												<?=nl2br(show_formatted_date($fetchRow['dateadded']));?>
                                                </td>
                                                <td class="smallText" align="center">
												<?
					                              echo $fetchRow['notes'];
					   
					                            ?>
                                                </td>
                                                
                                                  <? 
												
										  }  ##############end of while###########
								?>
                                            </table>
										  </td>
                                          
                                        </tr>
										<?php
										}
										?>
                                      </table></td>
                                  </tr>
                                </form>
                              </table></td>
                          </tr>
                        </table></td>
                    </tr>
                  </table>
                  
                  <table cellpadding="0" cellspacing="0" border="0">
                    <tr>
                      <td><img src="images/1_q4.gif" border="0" alt="" width="10" height="10"></td>
                      <td style="width:100%; background-image:url(images/1_li1.gif)"></td>
                      <td><img src="images/1_q3.gif" border="0" alt="" width="10" height="10"></td>
                    </tr>
                  </table></td>
                
                <td class="col_right">
                  <table border="0"cellspacing="0" cellpadding="0" class="box_width_right">
                    <tr>
                      <td></td>
                      <td width="100%"><table border="0" cellspacing="0" cellpadding="0">
                          <tr>
                            <td></td>
                          </tr>
                        </table></td>
                    </tr>
                  </table>
                  
                </td>
              </tr>
            </table>
            
            
          </td>
        </tr>
        <tr>
          <td><table cellpadding="0" cellspacing="0" border="0" style="height:98px; background-image:url(images/bot.gif)">
              <tr>
                <td><table cellpadding="0" cellspacing="0" border="0" class="footer">
                    <tr>
                      <td height="77"><img src="images/spacer.gif" border="0" alt="" width="25" height="1"></td>
                      <td style="width:207px"><br style="line-height:49px">
                        <img src="images/p1.gif" border="0" alt="" width="145" height="24"><br></td>
                      <td style="width:532px">&nbsp;</td>
                    </tr>
                  </table></td>
              </tr>
            </table></td>
        </tr>
      </table></td>
  </tr>
</table>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
  <tr>
    <td align="center"></td>
  </tr>
</table>

</body>

</html>
